#include "algostuff.h"
using namespace std;

void transform1()
{
	vector<int> coll1;
	list<int> coll2;

	INSERT_ELEMENTS(coll1, 1, 9);
	PRINT_ELEMENTS(coll1, "coll1: ");

	// negate all elements in coll1
	transform(coll1.cbegin(), coll1.cend(),
		coll1.begin(),
		negate<int>());
	PRINT_ELEMENTS(coll1, "negated: ");

	// transform elements of coll1 into coll2 with ten times their value
	transform(coll1.cbegin(), coll1.cend(),
		back_inserter(coll2),
		bind(multiplies<int>(), std::placeholders::_1, 10));
	PRINT_ELEMENTS(coll2, "coll2: ");

	// print coll2 negatively and in reverse order
	transform(coll2.crbegin(), coll2.crend(),
		ostream_iterator<int>(cout, " "),
		[](int elem) {
		return -elem;
	});
	cout << endl;
}

void transform2()
{
	vector<int> coll1;
	list<int> coll2;

	INSERT_ELEMENTS(coll1, 1, 9);
	PRINT_ELEMENTS(coll1, "coll1: ");

	// square each element
	transform(coll1.cbegin(), coll1.cend(),
		coll1.cbegin(),
		coll1.begin(),
		multiplies<int>());
	PRINT_ELEMENTS(coll1, "squared: ");

	// add each element traversed forward with each element traversed backward
	// and insert result into coll2
	transform(coll1.cbegin(), coll1.cend(),
		coll1.crbegin(),
		back_inserter(coll2),
		plus<int>());
	PRINT_ELEMENTS(coll2, "coll2: ");

	// print differences of two corresponding elements
	cout << "diff: ";
	transform(coll1.cbegin(), coll1.cend(),
		coll2.cbegin(),
		ostream_iterator<int>(cout, " "),
		minus<int>());
	cout << endl;
}